//
// Created by 11510 on 2024/7/4.
//

#ifndef DAY71_MUTEXLOCK_H
#define DAY71_MUTEXLOCK_H
#include <pthread.h>


class MutexLock {
private:
    pthread_mutex_t mutex;
public:
    MutexLock(){
        pthread_mutex_init(&mutex, NULL);
    }
    ~MutexLock(){
        pthread_mutex_destroy(&mutex);
    }
    void lock(){
        pthread_mutex_lock(&mutex);
    }
    void unlock(){
        pthread_mutex_unlock(&mutex);
    }
    int tryLock(){
        return pthread_mutex_trylock(&mutex);
    }
    pthread_mutex_t* operator&(){
        return &mutex;
    }
};


#endif //DAY71_MUTEXLOCK_H
